if (((cardValue = King) and not ((grid[0][0] = Empty) or (grid[0][3] = Empty) or (grid[3][0] = Empty) or (grid[3][3] = Empty))) or ((cardValue = Queen) and not ((grid[1][0] = Empty) or (grid[2][0] = Empty) or (grid[1][3] = Empty) or (grid[2][3] = Empty))) or ((cardValue = Jack) and not ((grid[0][1] = Empty) or (grid[0][2] = Empty) or (grid[3][1] = Empty) or (grid[3][2] = Empty)))) then
begin
gameInProgress := false;
PromptMessage(msgGameOver);
end;
end; {DrawNewCard}
procedure DrawSquare (x: Integer; y: Integer);
var
myRect: Rect;
begin
myRect.top := y * 64;
myRect.bottom := myRect.top + 65;
myRect.left := x * 64;
myRect.right := myRect.left + 65;
ForeColor(blueColor);
FrameRect(myRect);
InsetRect(myRect, 1, 1);
if (colorQDAvail) then
begin
RGBBackColor(litGray);
EraseRect(myRect);
ForeColor(whiteColor);
FrameRect(myRect);
InsetRect(myRect, 1, 1);
FrameRect(myRect);
InsetRect(myRect, -1, -1);
RGBForeColor(drkGray);
MoveTo(myRect.right - 1, myRect.top);
LineTo(myRect.right - 1, myRect.bottom - 1);
LineTo(myRect.left, myRect.bottom - 1);
LineTo(myRect.left + 1, myRect.bottom - 2);
LineTo(myRect.right - 2, myRect.bottom - 2);
LineTo(myRect.right - 2, myRect.top + 1);
end
else
begin
BackColor(whiteColor);
EraseRect(myRect);
end;
InsetRect(myRect, -1, -1);
if (grid[x][y] <> Empty) then
begin
DrawCard(grid[x][y], x, y);
if (multiple[x][y]) then
begin
myRect.top := (y * 64) + 10;
myRect.left := (x * 64) + 30;
myRect.bottom := myRect.top + 16;
myRect.right := myRect.left + 16;
ForeColor(blueColor);
if (colorQDAvail) then
RGBBackColor(midGray)
else
BackColor(whiteColor);
DrawSICN(myRect, suits, 4);
end;
end
else
begin
LabelGrid(x, y);
end;
end; {DrawSquare}
procedure FinishSelecting;
var
myRect: Rect;
count, count2: Integer;
begin
ClearMessage;
for count := 0 to 3 do
begin
for count2 := 0 to 3 do
begin
if (multiple[count][count2] = true) then
begin
multiple[count][count2] := false;
DrawSquare(count, count2);
end;
if (grid[count][count2] = Empty) then
begin
selectingMultiples := false;
end;
end;
end;
if (selectingMultiples) then
begin
gameInProgress := false;
selectingMultiples := false;
ClearMessage;
PromptMessage(msgGameOver);
Exit(FinishSelecting);
end;
DrawNewCard;
end; {FinishSelecting}
procedure SelectMultiples (var wherePtr: Point);
var
myRect: Rect;
where: Point;
total, count, count2: Integer;
begin
total := 0;
where := wherePtr;
where.h := BSR(where.h, 6);
where.v := BSR(where.v, 6);
if (where.v > 3) then
begin
FinishSelecting;
Exit(SelectMultiples);
end;
for count := 0 to 3 do
begin
for count2 := 0 to 3 do
begin
if (multiple[count][count2]) then
total := total + FindValue(grid[count][count2]);
end;
end;
if (multiple[where.h][where.v]) then
begin
multiple[where.h][where.v] := false;
DrawSquare(where.h, where.v);
Exit(SelectMultiples);
end
else
begin
total := total + FindValue(grid[where.h][where.v]);
if (total > 10) then
Exit(SelectMultiples);
multiple[where.h][where.v] := true;
DrawSquare(where.h, where.v);
if (total = 10) then
for count := 0 to 3 do
for count2 := 0 to 3 do
if (multiple[count][count2]) then
begin
grid[count][count2] := Empty;
multiple[count][count2] := false;
DrawSquare(count, count2);
end;
end;
end; {SelectMultiples}
procedure StartSelecting;
begin
ClearMessage;
PromptMessage(msgSelectMultOf10);
end;
procedure PlaceCards (var wherePtr: Point);
var
where: Point;
currentCard, cardValue: Byte;
count, count2: Integer;
begin
where := wherePtr;
where.h := BSR(where.h, 6);
where.v := BSR(where.v, 6);
if (where.v > 3) then
Exit(PlaceCards);
if (grid[where.h][where.v] <> Empty) then
Exit(PlaceCards);
currentCard := deck[deckPos];
cardValue := FindValue(currentCard);
{These huge if's could use some rewriting to be truly efficient.}
if ((cardValue = King) and not (((where.h = 0) or (where.h = 3)) and ((where.v = 0) or (where.v = 3)))) then
Exit(PlaceCards);
if ((cardValue = Queen) and not (((where.h = 1) and (where.v = 0)) or ((where.h = 2) and (where.v = 0)) or ((where.h = 1) and (where.v = 3)) or ((where.h = 2) and (where.v = 3)))) then
Exit(PlaceCards);
if ((cardValue = Jack) and not (((where.h = 0) and (where.v = 1)) or ((where.h = 0) and (where.v = 2)) or ((where.h = 3) and (where.v = 1)) or ((where.h = 3) and (where.v = 2)))) then
Exit(PlaceCards);
grid[where.h][where.v] := currentCard;
DrawCard(currentCard, where.h, where.v);
if ((FindValue(grid[0][0]) = King) and (FindValue(grid[0][3]) = King) and (FindValue(grid[3][0]) = King) and (FindValue(grid[3][3]) = King) and (FindValue(grid[1][0]) = Queen) and (FindValue(grid[2][0]) = Queen) and (FindValue(grid[1][3]) = Queen) and (FindValue(grid[2][3]) = Queen) and (FindValue(grid[0][1]) = Jack) and (FindValue(grid[0][2]) = Jack) and (FindValue(grid[3][1]) = Jack) and (FindValue(grid[3][2]) = Jack)) then
begin
ClearMessage;
PromptMessage(msgYouWin);
gameInProgress := false;
Exit(PlaceCards);
end;
selectingMultiples := true;
for count := 0 to 3 do
begin
for count2 := 0 to 3 do
begin
if (grid[count][count2] = Empty) then
selectingMultiples := false;
end;
end;
if (selectingMultiples) then
begin
StartSelecting;
Exit(PlaceCards);
end;
DrawNewCard;
end;
procedure RedrawWindow;
var
count, count2: Integer;
myRect: Rect;
begin
for count := 0 to 3 do
for count2 := 0 to 3 do
DrawSquare(count2, count);
if (selectingMultiples) then
PromptMessage(msgSelectMultOf10)
else if deckPos < 52 then
DrawCard(deck[deckPos], 3, 4)
else
DrawCard(Empty, 3, 4);
if (not gameInProgress) then
PromptMessage(msgGameOver);
end; {RedrawWindow}
procedure Initialize;
var
thisSysInfo: SysEnvRec;
err: OSErr;
begin
{$IFC UNDEFINED THINK_PASCAL}
MaxApplZone;
MoreMasters;
InitGraf(qd.thePort);
InitFonts;
FlushEvents(everyEvent, 0);
InitWindows;
InitMenus;
TEInit;
InitDialogs(nil);
InitCursor;
{$ENDC}
{ GetDateTime( (unsigned long * ) & randSeed ) ); / / seed the random # generator }